{literal}
<script type="text/javascript"  language="JavaScript">
<!--
var addedTemplateCount = 0;
function addTemplate(reportId)
{
	var tbl = document.getElementById("template");

	var input = document.createElement("input");
	input.name = "new_templates[" + addedTemplateCount + "][name]";
	input.type = "text";
	input.value = "New Template";
	input.size = "20";

	var input2 = document.createElement("input");
	input2.name = "new_templates[" + addedTemplateCount + "][custom_id]";
	input2.type = "text";
	input2.value = "";
	input2.size = "20";

	var bdown = document.createElement("a");
	bdown.href ="download_template/0?report_id="+reportId;
	bdown.appendChild(document.createTextNode("Download"));

	var bdelete = document.createElement("a");
	bdelete.setAttribute('onClick',"deleteNewRow(this); return false;");
	bdelete.href = "#";
	bdelete.appendChild(document.createTextNode("Delete"));

	var ifile = document.createElement("input");
	ifile.type="file";
	ifile.name="new_template_file[]";
	ifile.size="20";



	var lastRow = tbl.rows.length;
	var row = tbl.insertRow(lastRow)

	var cell1 = row.insertCell(0);
	var cell2 = row.insertCell(1);
	var cell3 = row.insertCell(2);
	var cell4 = row.insertCell(3);
	var cell5 = row.insertCell(4);

	cell1.appendChild(input);
	cell2.appendChild(input2);
	cell3.appendChild(bdown);
	cell4.appendChild(ifile);
	cell5.appendChild(bdelete);
	
	addedTemplateCount++;
}
function deleteNewRow(button) {
	var name = button.parentNode.parentNode.firstChild.firstChild.value;
	if (confirm("Are you sure you want to delete template: "+name)) {
		var tbl = button.parentNode.parentNode.parentNode.parentNode;
		tbl.deleteRow(button.parentNode.parentNode.sectionRowIndex);
	}
}
function deleteTemplate(button,template_id) {
	var name = button.parentNode.parentNode.getElementsByTagName('td').item(0).firstChild.value;
	if (confirm("Are you sure you want to delete template: "+name)) {
		var tbl = button.parentNode.parentNode.parentNode.parentNode;
		tbl.deleteRow(button.parentNode.parentNode.sectionRowIndex);

		var hidden = document.createElement("input");
		hidden.name = "deleted_templates[]";
		hidden.value = template_id;
		hidden.type = "hidden";
		document.getElementById('template').parentNode.appendChild(hidden);
	}
}
-->
</script>
<style type="text/css">
	#template td {
		padding: 1px;
	}
</style>
{/literal}
<div id="FormMessageBox"></div>
<table width="100%"  border="0" cellspacing="0" cellpadding="8">
            <tr>
		    <td>
			    {if $report->id > 0}
			    <h3 style="margin: 0px; padding: 0px;">Edit Report</h3>
			    {else}
			    <h3 style="margin: 0px; padding: 0px;">Add Report</h3>
			    {/if}
{clni_form action=$TOP_ACTION autocomplete="off" process=$PROCESS name="report" id="reportForm"}
{clni_register_message_target formId="reportForm" targetId="FormMessageBox"}
	  {*{if $report->get('id') > 0}
		<h3>Report Details for <i>{$report->get_label()}</i></h3>
		{/if}*}
		<fieldset class="radio" style="width:50%; height:600px;">
		<legend>Report Definition</legend>
<table>
	<tr>
		<td><label>{l}Title{/l}:</label></td>
		<td><input type="text" name="label" size="30" value="{$report->get_label()}"></td>
	</tr>
	<tr>
		<td><label>{l}Description{/l}:</label></td>
		<td><textarea name="description" rows="2" cols="40" wrap="virtual">{$report->get_description()}</textarea></td>
	</tr>
	<tr>
		<td><label>{l}Custom ID{/l}:</label></td>
		<td><input type="text" name="custom_id" id="custom_id" size="30" value="{$report->get_custom_id()}" /></td>
	</tr>
	<tr>
		<td><label for="showSequence">{l}Show Sequence ID{/l}:</label></td>
		<td><input type="hidden" name="show_sequence" value="0">
			<input id="showSequence" type="checkbox" name="show_sequence" value="1" {if $report->get('show_sequence')}CHECKED{/if}>
		</td>
	</tr>
	<tr>
		<td><label>{l}Snapshot Report{/l}:</label></td>
		<td><select name="snapshot_style">
				<option value='0'{if $report->get('snapshot_style') == 0} SELECTED{/if}>Never</option>
				<option value='1'{if $report->get('snapshot_style') == 1} SELECTED{/if}>Always</option>
				<option value='2'{if $report->get('snapshot_style') == 2} SELECTED{/if}>Manual</option>
			</select>
		</td>
	</tr>
	{if $systemReports}
	<tr>
		<td><label>{l}System Report{/l}:</label></td>
		<td><select name="system_report">
				<option value="">Normal Report</option>
				{html_options options=$systemReports selected=$report->get('system_report')}
			</select>
		</td>
	</tr>
	{/if}
	<tr>
		<td><label>{l}Query{/l}:</label></td>
		<td><textarea name="query" rows="10" cols="80" wrap="virtual">{$report->get('query')}</textarea></td>
	</tr>
	<tr>
		<td colspan="2" align="center"><br>
		{if $report->id > 0}
		<input type="submit" name="submit" value="Update Report">
		{else}
		<input type="submit" name="submit" value="Add Report">
		{/if}
		</td>
	</tr>
</table>
	</fieldset>

	{if $report->id > 0}
	<fieldset class="radio" style="width:50%;">
		<legend>Report Templates</legend>
		{*<p>Click on a Title to edit the template</p>*}
		<table class="grid" id="template">
			<tr>
				<th>Title</th><th>Custom ID</th><th>Download</th><th>Delete</th><th>Upload</th><th>Preview</th>
			</tr>
			{foreach from=$templates item=template}
			<tr>
				<td><input type="text" value="{$template.name}" size="20" name="templates[{$template.report_template_id}][name]"
					><input type="hidden" value="{$template.is_default}" name="templates[{$template.report_template_id}][is_default]"
					><input type="hidden" value="{$template.report_id}" name="templates[{$template.report_template_id}][report_id]">
				</td>
				{if $template.is_default == "yes"}
				<td>N/A</td>
				<td>N/A</td>
				<td>N/A</td>
				<td>N/A</td>
				{else}
				<td><input type="text" value="{$template.custom_id}" size="20" name="templates[{$template.report_template_id}][custom_id]"></td>
				<td><a href="{$DOWNLOAD_ACTION}template_id={$template.report_template_id}">Download</a></td>
				<td><input type="file" name="template[{$template.report_template_id}][file]" size="20"></td>
				<td><a OnClick="deleteTemplate(this,{$template.report_template_id}); return false;" href="#">Delete</a></td>
				{/if}
				<td>
				{if $template.pdf}<a href="{link controller="Report" action="report" defaultArg=$template.report_id pageType="minimal"}report_template_id={$template.report_template_id}&binaryHeader=true" target="preview">XML</a> /{/if}
				<a href="{link controller="Report" action="report" defaultArg=$template.report_id pageType="minimal"}report_template_id={$template.report_template_id}" target="preview">Load</a></td>
			</tr>
			{/foreach}
		</table>
		<input type="button" OnClick="addTemplate({$template.report_id});" value="Add a new Template" >
		<input type="submit" name="submit" value="Update Templates">
	</fieldset>
	{/if}
<input type="hidden" name="id" value="{$report->get_id()}">
<input type="hidden" name="process" value="{$PROCESS}">
</form>
	{$visualizations}
</td></tr>
</table>
<fieldset style="float:left;width:100%; height:600px;" class="radio">
<legend>Preview</legend>
<iframe name="preview" style="width:100%;height:575px;">
</iframe>
</fieldset>
{clni_register_validation id="custom_id" rules="required|alphanum" message="Custom ID must be alphanumeric and contain no spaces."}
